#include "../bulk_storage/bulk_storage.h"
//#include "../pdb_index/atom.h"
#include "aa_util.h"
#include <assert.h>

int main (int argc, char * argv[]) {
  int i;
  assert (argc % 2); // We need to have an even number of arguments. (Two for each atom store.)  Since argc = number of arguments + 1, we're all set.

  for(i = 1; i < argc; i+=2) {
    struct store * s = store_open_cached(argv[i], argv[i+1], sizeof(struct atom), 100, 100000);
    struct atom * a;
    struct xyz_int xyz;
    struct xyz_int xyz_mc; //mass center added by Zhang Fa
    off_t i = 1;
    a = store_read(s,i);
    
    while(a->name[0]) {
      off_t start;
      off_t stop;
      int ret;
      find_aa_range(s, i, &start, &stop);
      
      ret  = calculate_aa_functional_group(s, start, stop, &xyz);
      
      calculate_aa_mass_center(s, start, stop, &xyz_mc );//test mass center by Fa

      printf("%d to %d:\t", (int)start, (int)stop);

      printf("MC: %d %d %d\t",xyz_mc.x, xyz_mc.y, xyz_mc.z);
      printf("active site (%d): %d %d %d\t", ret, xyz.x, xyz.y, xyz.z);
      atom_print(a);
      store_release(s, i);
      i++;
      a = store_read(s, i);

    }
    store_release(s,i);
    store_close (s);
  }
  
  return 0;
}
